//
//  XNavigationController.swift
//  WeiBoReDo
//
//  Created by 放学跟鸽走 on 2017/4/8.
//  Copyright © 2017年 放学跟鸽走. All rights reserved.
//

import UIKit

/// 导航控制器
class XNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBar.isHidden = true
        // Do any additional setup after loading the view.
    }
    ///在MaintabCtr中初始化控制器的时候，就会调用pushViewController将根控制器push到栈底，
    ///在Tabbar按钮点击切换控制器的时候，也会调用这个方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        print("push \(viewController)")
        //判断是不是根控制器，在初始化的时候以及切换根控制器的时候，根控制器的子控制器0
        if(childViewControllers.count > 0){
            viewController.hidesBottomBarWhenPushed=true
            if let vc = viewController as? XBaseController{
                //设置标题
                var title = "返回"
                if(childViewControllers.count==1){
                    title = childViewControllers.first?.title ?? "返回"
                }
                vc.navBarItem.leftBarButtonItem = UIBarButtonItem(title:title , target: self, action: #selector(preOne), isBack: true)
            }
        }
        super.pushViewController(viewController, animated: animated)
        
    }
    /// 返回按钮点击事件
    func preOne(){
        popViewController(animated: true)
    }
    
    
}
